﻿@model CustomerModel
@inject AdminAreaSettings adminAreaSettings
<div class="panel panel-default">
    <vc:admin-widget widget-zone="customer_details_addresses_top" additional-data="Model"/>
    <div class="panel-body">
        <div id="customer-addresses-grid"></div>
    </div>
    <div class="panel-footer">
        <button type="button" class="k-button" onclick="location.href='@Url.Action("AddressCreate", new { customerId = Model.Id, area = Constants.AreaAdmin })'"><i class="fa fa-plus"></i>&nbsp;@Loc["Admin.Customers.Customers.Addresses.AddButton"]</button>
    </div>
    <vc:admin-widget widget-zone="customer_details_addresses_bottom" additional-data="Model"/>
</div>

<script>
$(document).ready(function () {
    $("#customer-addresses-grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    url: "@Html.Raw(Url.Action("AddressesSelect", "Customer", new { customerId = Model.Id, area = Constants.AreaAdmin }))",
                    type: "POST",
                    dataType: "json",
                    data: addAntiForgeryToken
                },
                destroy: {
                    url: "@Html.Raw(Url.Action("AddressDelete", "Customer", new { customerId = Model.Id, area = Constants.AreaAdmin }))",
                    type: "POST",
                    dataType: "json",
                    data: addAntiForgeryToken
                }
            },
            schema: {
                data: "Data",
                total: "Total",
                errors: "Errors",
                model: {
                    id: "Id"
                }
            },
            error: function(e) {
                display_kendoui_grid_error(e);
                // Cancel the changes
                this.cancelChanges();
            },
            pageSize: @(adminAreaSettings.DefaultGridPageSize),
        },
        autoBind: false,
        pageable: {
            refresh: true,
            pageSizes: [@(adminAreaSettings.GridPageSizes)]
        },
        editable: {
            confirmation: true,
            mode: "inline"
        },
        scrollable: false,
        columns: [{
            field: "FirstName",
            title: "@Loc["Admin.Address.Fields.FirstName"]"
        }, {
            field: "LastName",
            title: "@Loc["Admin.Address.Fields.LastName"]"
        }, {
            field: "Email",
            title: "@Loc["Admin.Address.Fields.Email"]"
        }, {
            field: "PhoneNumber",
            title: "@Loc["Admin.Address.Fields.PhoneNumber"]",
            minScreenWidth: 1020,
        }, {
            field: "AddressHtml",
            title: "@Loc["Admin.Address"]",
            encoded: false
        }, {
            field: "Id",
            title: "@Loc["Admin.Common.Edit"]",
            width: 100,
            template: '<a class="k-button" href="@Url.Action("AddressEdit", "Customer", new { area = Constants.AreaAdmin })?customerId=@Model.Id&addressid=#=Id#"><span class="k-icon k-i-edit"></span>&nbsp;&nbsp;@Loc["Admin.Common.Edit"]</a>'
        }, {
            command: { name: "destroy", text: "@Loc["Admin.Common.Delete"]" },
            title: "@Loc["Admin.Common.Delete"]",
            width: 100
        }]
    });
});
</script>